package com.kingint.web.util;

import com.kingint.mbg.sys.entity.UmsMember;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Component;

@Component
public class UserIdUtil {

    /**
     * 获取登录用户对象
     * @return
     */
    public UmsMember getUser(){
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
//        String currentPrincipalName = authentication.principal;
        UmsMember user = (UmsMember) authentication.getPrincipal();
        return user;
    }

    /**
     * 获取登录用户id
     * @return
     */
    public Long getUserId(){
        UmsMember user = getUser();
        return user.getId();
    }
}
